package com.yuandengta.yomall.gateway.config;

import com.yuandengta.common.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * JWT属性类 {@link JwtProperties}
 *
 * @author Kevin
 * @email: 178676392@qq.com
 */
@ConfigurationProperties(prefix = "auth.jwt")
@Slf4j
@Data
public class JwtProperties {

    private String pubKeyPath;
    private PublicKey publicKey;

    private String cookieName;

    @PostConstruct
    public void init(){
        try {
            // 获取公钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("初始化公钥失败！", e);
            throw new RuntimeException();
        }
    }
}
